﻿package core.ui.options
{
    import core.event.*;
    import core.ui.controls.*;
    import flash.display.*;
    import flash.events.*;

    public class GradientOptions extends Sprite implements IToolOptions
    {
        var ed:Tuyitu;
        var opacity:Dropslider;
        var pattern:GradientPad;
        var blendmode:Dropdown;
        var linear:Radiobutton;
        var radial:Radiobutton;
        var method:Dropdown;

        public function GradientOptions(param1:Tuyitu)
        {
            this.ed = param1;
            var _loc_2:* = 10;
            var _loc_3:* = 15;
            var _loc_4:* = new Literal("rm_opacity");
            _loc_4.x = _loc_2;
            _loc_4.y = 2;
            addChild(_loc_4);
            _loc_2 = _loc_2 + _loc_4.width;
            this.opacity = new Dropslider(50, 0, 100, 100);
            this.opacity.x = _loc_2;
            this.opacity.y = 2;
            addChild(this.opacity);
            _loc_2 = _loc_2 + (50 + _loc_3);
            var _loc_5:* = new BarSplit();
            _loc_5.x = _loc_2;
            addChild(_loc_5);
            _loc_2 = _loc_2 + (2 + _loc_3);
            _loc_2 = _loc_2 - 5;
            var _loc_6:* = new Literal("rm_gradient");
            _loc_6.x = _loc_2;
            _loc_6.y = 2;
            addChild(_loc_6);
            _loc_2 = _loc_2 + _loc_6.width;
            this.pattern = new GradientPad(new Array(16777215, 0), new Array(1, 1), new Array(0, 255));
            this.pattern.addEventListener(MouseEvent.MOUSE_DOWN, this.GradientMouseDown);
            this.pattern.x = _loc_2;
            this.pattern.y = 2;
            addChild(this.pattern);
            _loc_2 = _loc_2 + (this.pattern.width + _loc_3);
            var _loc_7:* = new BarSplit();
            _loc_7.x = _loc_2;
            addChild(_loc_7);
            _loc_2 = _loc_2 + (2 + _loc_3);
            var _loc_8:* = new Literal("rm_type");
            _loc_8.x = _loc_2;
            _loc_8.y = 2;
            addChild(_loc_8);
            _loc_2 = _loc_2 + (_loc_8.width + 4);
            this.linear = new Radiobutton("rm_linear");
            this.linear.addEventListener(ChangeEvent.CHANGE, this.TypeClick);
            this.linear.x = _loc_2;
            this.linear.y = 3;
            this.linear.Check();
            addChild(this.linear);
            _loc_2 = _loc_2 + (this.linear.width + 10);
            this.radial = new Radiobutton("rm_radial");
            this.radial.addEventListener(ChangeEvent.CHANGE, this.TypeClick);
            this.radial.x = _loc_2;
            this.radial.y = 3;
            addChild(this.radial);
            _loc_2 = _loc_2 + (this.radial.width + _loc_3);
            var _loc_9:* = new BarSplit();
            _loc_9.x = _loc_2;
            addChild(_loc_9);
            _loc_2 = _loc_2 + (2 + _loc_3);
            var _loc_10:* = new Literal("rm_spread_method");
            _loc_10.x = _loc_2;
            _loc_10.y = 2;
            addChild(_loc_10);
            _loc_2 = _loc_2 + (_loc_10.width + 4);
            this.method = new Dropdown(90, 90);
            this.method.x = _loc_2;
            this.method.y = 2;
            this.method.AddItem(U.RM("rm_pad"), "pad", true);
            this.method.AddItem(U.RM("rm_reflect"), "reflect");
            this.method.AddItem(U.RM("rm_repeat"), "repeat");
            this.method.Bind();
            addChild(this.method);
            _loc_2 = _loc_2 + (this.method.width + _loc_3);
            var _loc_11:* = new BarSplit();
            _loc_11.x = _loc_2;
            addChild(_loc_11);
            _loc_2 = _loc_2 + (2 + _loc_3);
            var _loc_12:* = new Literal("rm_mode");
            _loc_12.x = _loc_2;
            _loc_12.y = 2;
            addChild(_loc_12);
            _loc_2 = _loc_2 + (_loc_12.width + 4);
            this.blendmode = new Dropdown(90, 90);
            this.blendmode.x = _loc_2;
            this.blendmode.y = 2;
            this.blendmode.AddItem("正常", "normal", true);
            this.blendmode.AddItem("添加", "add");
            this.blendmode.AddItem("透明度", "alpha");
            this.blendmode.AddItem("变暗", "darken");
            this.blendmode.AddItem("差值", "difference");
            this.blendmode.AddItem("排除", "erase");
            this.blendmode.AddItem("强光", "hardlight");
            this.blendmode.AddItem("倒置", "invert");
            this.blendmode.AddItem("层叠", "layer");
            this.blendmode.AddItem("变亮", "lighten");
            this.blendmode.AddItem("正片叠底", "multiply");
            this.blendmode.AddItem("叠加", "overlay");
            this.blendmode.AddItem("屏幕", "screen");
            this.blendmode.AddItem("减淡", "subtract");
            this.blendmode.Bind();
            addChild(this.blendmode);
            _loc_2 = _loc_2 + (this.blendmode.width + _loc_3);
            var _loc_13:* = new BarSplit();
            _loc_13.x = _loc_2;
            addChild(_loc_13);
            _loc_2 = _loc_2 + (2 + _loc_3);
            return;
        }// end function

        private function TypeClick(event:ChangeEvent) : void
        {
            if (event.target != this.linear)
            {
                this.linear.Check(false);
            }
            else
            {
                this.radial.Check(false);
            }
            return;
        }// end function

        private function GradientMouseDown(event:MouseEvent) : void
        {
            this.ed.options.gradients.Show(this.pattern);
            this.ed.options.gradients.x = this.pattern.x + 40;
            this.ed.options.gradients.y = this.pattern.y + 28;
            return;
        }// end function

        public function get options() : Object
        {
            return {opacity:this.opacity.value / 100, colors:this.pattern.colors, alphas:this.pattern.alphas, ratios:this.pattern.ratios, type:this.linear.checked ? ("linear") : ("radial"), method:this.method.value, blendmode:this.blendmode.value};
        }// end function

    }
}
